package com.aixingfu.sports.Adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.text.TextUtils;

import com.aixingfu.sports.Model.SearchModel;
import com.aixingfu.sports.R;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Author : lv
 * Time : 2019.04.30 0011
 * Description :
 */
public class MemberListAdapter extends BaseQuickAdapter<SearchModel.DataBean, BaseViewHolder> {

    private Context context;

    public MemberListAdapter(int layoutResId, @Nullable List<SearchModel.DataBean> data) {
        super(layoutResId, data);
    }

    public MemberListAdapter(Context context, int layoutResId, @Nullable List<SearchModel.DataBean> data) {
        super(layoutResId, data);

        this.context = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, SearchModel.DataBean item) {
    helper.addOnClickListener(R.id.tv_buy_class)
            .addOnClickListener(R.id.tv_buy_card)
            .setText(R.id.tv_name,"会员姓名："+item.getUsername())
            .setText(R.id.tv_phone,"手机号："+ item.getMobile())
    .setText(R.id.tv_state,"会员状态：" + item.getIs_pos());
        String last_time = item.getLast_time();
        if ("1970-01-01".equals(last_time)){
            helper.setText(R.id.tv_time,"最近到场："+ "暂无进馆记录");
        }else {
            helper.setText(R.id.tv_time,"最近到场："+ item.getLast_time());
        }
        String birth_date = item.getBirth_date();
        if (TextUtils.isEmpty(birth_date)){
            helper.setText(R.id.tv_birthday,"生日：");
        }else {
            helper.setText(R.id.tv_birthday,"生日：" + item.getBirth_date());
        }
        String sex = item.getSex();
        if ("1".equals(sex)){
            helper.setText(R.id.tv_sex,"性别："+"男");
        }else {
            helper.setText(R.id.tv_sex,"性别："+"女");
        }
        String status = item.getStatus();
        if ("0".equals(status)){
            helper.setText(R.id.tv_state,"会员状态："+"待审核");
        }else if ("1".equals(status)){
            helper.setText(R.id.tv_state,"会员状态："+"正常");
        }else if ("2".equals(status)){
            helper.setText(R.id.tv_state,"会员状态："+"禁用");
        }
        CircleImageView logoview = helper.getView(R.id.iv_head);
        RequestOptions options = new RequestOptions()
                .centerCrop()
                .dontAnimate()
                .placeholder(R.mipmap.touxiang)
                .diskCacheStrategy(DiskCacheStrategy.ALL);
        Glide.with(context)
                .load(item.getAvatar_url())
                .apply(options)
                .into(logoview);
    }
}
